#!/bin/bash

echo "╔════════════════════════════════════════════════════════════════════════════╗"
echo "║              🚀 启动生产环境（完整Docker部署）                               ║"
echo "╚════════════════════════════════════════════════════════════════════════════╝"
echo ""

SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
COMPOSE_FILE_PATH="$SCRIPT_DIR/docker-compose.yml"
export COMPOSE_FILE="$COMPOSE_FILE_PATH"

# 步骤1: 构建并启动所有服务
echo "📦 步骤1: 构建并启动所有服务..."
docker-compose up -d --build

echo ""
echo "⏳ 等待所有服务启动..."
sleep 30

# 步骤2: 检查服务状态
echo ""
echo "📊 服务状态:"
docker-compose ps

echo ""
echo "📊 健康检查:"
docker-compose exec nestjs-backend node -e "require('http').get('http://localhost:3000/health', (r) => {console.log('NestJS:', r.statusCode === 200 ? '✅ 健康' : '❌ 异常')})" 2>/dev/null || echo "NestJS: ⏳ 等待启动..."

echo ""
echo "✅ 所有服务已启动！"
echo ""
echo "🌐 访问地址:"
echo "   Admin管理面板: http://localhost"
echo "   NestJS API:    http://localhost:3000"
echo "   MySQL:         localhost:3306"
echo "   Redis:         localhost:6379"
echo ""
echo "📋 常用命令:"
echo "   查看日志: docker-compose logs -f"
echo "   停止服务: docker-compose down"
echo "   重启服务: docker-compose restart"
echo ""
